﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace DisplayBoardInfo.Server.Forms.Board
{
    public partial class BoardWindow : Form
    {
        List<Board> boards;
        int[] index = new int[0];
        int currentIndex = 0;
        Timer t = null;

        public List<Board> Boards
        {
            get { return boards; }
            set 
            {
                if (value.Count > 0)
                {
                    boards = value;
                }
                else 
                {
                    elementHost1.Child = new Wall();
                }
            }
        }

        public int[] DisplayedBoardIndex
        {
            get { return index; }
            set 
            {
                    index = value;
                    if (value.Count() > 0) elementHost1.Child = boards[index[0]];
                    else elementHost1.Child = new Wall();
            }
        }

        public int DisplayInterval
        {
            get 
            {
                return (int)(t.Interval / 1000);
            }

            set
            {
                t.Interval = value * 1000;
            }
        }

        public BoardWindow()
        {
            InitializeComponent();
            elementHost1.Child = new Wall();

            //
            //Set to full screen
            this.Left = 0;
            this.Top = 0;
            this.Width = Screen.PrimaryScreen.Bounds.Width;
            this.Height = Screen.PrimaryScreen.Bounds.Height;

            this.FormClosing += new FormClosingEventHandler(BoardWindow_FormClosing);

            t = new Timer();
            t.Interval = 10000;
            t.Tick += new EventHandler(t_Tick);
            t.Start();
        }

        void t_Tick(object sender, EventArgs e)
        {
            if (index.Count() > 1)
            {
                currentIndex++;
                if (currentIndex >= index.Count()) currentIndex = 0;
                elementHost1.Child = boards[index[currentIndex]];
            }
        }

        void BoardWindow_FormClosing(object sender, FormClosingEventArgs e)
        {
            elementHost1.Child = null;
        }

        ///// <summary>
        ///// Adds new board to display
        ///// </summary>
        //public void AddBoard(Board board)
        //{
        //    boards.Add(board);
            
        //    elementHost1.Child = board;
        //}
    }
}
